﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using EntityLayer;
namespace DataLayer.DAO
{
    public class clsT_CuadernoDAO
    {
        private BDCONTRALORIAEntities ContextoDeObjs = new BDCONTRALORIAEntities();

        public bool InsertarVarios(List<T_Cuaderno> Obj, string CO_legajo)
        {
            try
            {
                ContextoDeObjs.ExecuteStoreCommand("delete T_Cuaderno where CO_legajo='" + CO_legajo + "'");

                foreach (T_Cuaderno item in Obj)
                {
                    ContextoDeObjs.AddObject("T_Cuaderno", item);
                }
                ContextoDeObjs.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
                throw;
            }
        }

        public bool Insertar(T_Cuaderno Obj)
        {
            try
            {
                ContextoDeObjs.AddObject("T_Cuaderno", Obj);
                ContextoDeObjs.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
                throw;
            }
        }

        public bool Modificar(T_Cuaderno obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("T_Cuaderno", obj);
                ContextoDeObjs.ObjectStateManager.ChangeObjectState(obj, System.Data.EntityState.Modified);
                ContextoDeObjs.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool Eliminar(T_Cuaderno obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("T_Cuaderno", obj);
                ContextoDeObjs.DeleteObject(obj);
                ContextoDeObjs.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public List<T_Cuaderno> listarCuaderno()
        {
            List<T_Cuaderno> listarCargos = new List<T_Cuaderno>();
            var q = from c in ContextoDeObjs.T_Cuaderno
                    select c;
            listarCargos = q.ToList();
            return listarCargos;
        }

        public List<T_Cuaderno> listarCuadernoCO_legajo(string CO_legajo)
        {
            List<T_Cuaderno> listarCuadernoCO_legajo = new List<T_Cuaderno>();
            var q = from c in ContextoDeObjs.T_Cuaderno
                    where c.CO_legajo == CO_legajo
                    select c;
            listarCuadernoCO_legajo = q.ToList();
            return listarCuadernoCO_legajo;
        }

        public List<V_Listar_Cuadernos> V_listarCuadernoCO_legajo(string CO_legajo)
        {
            List<V_Listar_Cuadernos> V_listarCuadernoCO_legajo = new List<V_Listar_Cuadernos>();
            var q = from c in ContextoDeObjs.V_Listar_Cuadernos
                    where c.CO_legajo == CO_legajo
                    select c;
            V_listarCuadernoCO_legajo = q.ToList();
            return V_listarCuadernoCO_legajo;
        }
    }
}
